< previous page page_468 next page >

Page 468
In Listing 12.1, you present a message to the user to confirm the intention to add a new record to the set. If the answer is No, the add operation is canceled.
Now let's add code that tells the user the add operation has been completed. Add the following code in the DBGrid1_AfterInsert event window:
Private Sub DBGrid1_AfterInsert()
    '
    ' tell user what you just did!
    '
    MsgBox "New record written to data set!", vbInformation,
    _ "DBGrid.AfterInsert"
End Sub
Now save and run the project. Go to the last row in the grid. Begin entering a new record. As soon as you press the first key, the confirmation message appears. (See Figure 12.14.)
0468-01.jpg
Figure 12.14.
Attempting to add a
record to the grid.
After you fill in all the columns and attempt to move to another record in the grid, you'll see the message telling you that the new record was added to the data set.
The Update Record Events
Now add some code that monitors attempts to update existing records. Add Listing 12.2 to the DBGrid1.BeforeUpdate event.
Type.gifListing 12.2. Code to monitor for attempted data updates.
Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
    '
    ' make user confirm update operation
    '
    Dim nResult As Integer
    '
    nResult = MsgBox("Write any changes to data set?",
    _ vbInformation + vbYesNo, "DBGrid.BeforeUpdate")
    If nResult = vbNo Then
        Cancel = True   ' ignore changes
        DBGrid1.ReBind  ' reset all values
    End If
End Sub

 
< previous page page_468 next page >

If you like this book, buy it!